var Action = require("../apiaction");
exports.shapanAPI = function(router){

    //创建活动
    router.all('/shapan/api/activity',function(req,res){

        var activity_name=req.param("activity_name");
        var activity_time=req.param("activity_time");
        var activity_group=req.param("activity_group");
        var activity_coach=req.param("activity_coach");
        var activity_Place="1";
        var params={
            activity_name:activity_name,
            activity_time:activity_time,
            activity_group:activity_group,
            activity_coach:activity_coach,
            activity_Place:activity_Place
        };
        Action.send(req,res,'/Activity/creatActivity',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //获得所有组名
    router.all('/shapan/api/groupNames',function(req,res){

        var activity_mid=req.param("activity_mid");
        var params={};
        params.activity_mid=activity_mid;

        Action.send(req,res,'/Group/groupNames',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //拿到人员信息,表格
    router.all('/shapan/api/roleFenpei',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var group_mid = req.param('group_mid');
        var role_mid = req.param('role_mid');
        var year_id = req.param('year_id');
        var activity_mid = req.param('activity_mid');

        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={
            pageIndex:page,
            pageSize:rows,
            year_id:year_id,
            activity_mid:activity_mid
        };

        if(group_mid!='undefined') {
            param.group_mid = group_mid;
        }

        if(role_mid!='undefined'){
            param.role_mid=role_mid;
        }


        Action.send(req,res,'/Ugry/informationShow',param,'POST',function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        });
    });

    //公司组建
    router.all('/shapan/api/newCompany',function(req,res){

        var group_name1=req.param("group_name1");
        var group_name2=req.param("group_name2");
        var group_name3=req.param("group_name3");
        var group_name4=req.param("group_name4");
        var group_name5=req.param("group_name5");
        var group_name6=req.param("group_name6");
        var activity_mid=req.param("activity_mid");

        var params={
            group_name1:group_name1,
            group_name2:group_name2,
            group_name3:group_name3,
            group_name4:group_name4,
            group_name5:group_name5,
            group_name6:group_name6,
            activity_mid:activity_mid
        };
        Action.send(req,res,'/Group/creatGroup',params,'GET',function(res,data){
            var json=JSON.parse(data);
            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //修改人员信息
    router.all('/shapan/api/groupedit',function(req,res){

        var group_mid=req.param("group_mid");
        var role_mid=req.param("role_mid");
        var user_mid=req.param("user_mid");
        var year_id=req.param("year_id");

        var params={
            group_mid:group_mid,
            role_mid:role_mid,
            user_mid:user_mid,
            year_id:year_id
        };

        Action.send(req,res,'/Ugry/creatroleAssignment',params,'GET',function(res,data){

            var json=JSON.parse(data);
            console.log(json);
            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //参数设定
    router.all('/shapan/api/parameter',function(req,res){

        var sales_profit=req.param("sales_profit");
        var market_share=req.param("market_share");
        var development=req.param("development");
        var team_capacity=req.param("team_capacity");
        var capital_pool=req.param("capital_pool");
        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");

        var params={
            sales_profit:sales_profit,
            market_share:market_share,
            team_capacity:team_capacity,
            development:development,
            capital_pool:capital_pool,
            activity_mid:activity_mid,
            year_id:year_id
        };

        Action.send(req,res,'/Index/parameter',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //获取研发决策
    router.all('/shapan/api/ResearchesShow',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");

        var params={
            activity_mid:activity_mid,
            year_id:year_id
        };

        Action.send(req,res,'/Researches/ResearchesShow',params,'GET',function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //经营决策 机器产线
    router.all('/shapan/api/beltlineShow',function(req,res){

        var group_mid = req.param('group_mid');
        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");
        var beltline_type = req.param('beltline_type');
        var state_one = req.param('state_one');
        var state_two = req.param('state_two');
        var state_three = req.param('state_three');

        var params={
            activity_mid:activity_mid,
            year_id:year_id,
            group_mid:group_mid,
            beltline_type:beltline_type,
            state_one:state_one,
            state_two:state_two,
            state_three:state_three
        };

        Action.send(req,res,'/Index/beltlineShow',params,'GET',function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //经营决策 工人产线
    router.all('/shapan/api/workShow',function(req,res){

        var group_mid = req.param('group_mid');
        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");
        var work_type = req.param('work_type');
        var work_state_one = req.param('work_state_one');
        var work_state_two = req.param('work_state_two');
        var work_state_three = req.param('work_state_three');

        var params={
            activity_mid:activity_mid,
            year_id:year_id,
            group_mid:group_mid,
            work_type:work_type,
            work_state_one:work_state_one,
            work_state_two:work_state_two,
            work_state_three:work_state_three
        };

        Action.send(req,res,'/Index/workShow',params,'GET',function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //经营决策 工人产线
    router.all('/shapan/api/financings',function(req,res){

        var group_mid = req.param('group_mid');
        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");
        var one_year = req.param('one_year');
        var two_year = req.param('two_year');

        var params={
            activity_mid:activity_mid,
            year_id:year_id,
            group_mid:group_mid,
            two_year:two_year,
            one_year:one_year
        };
        Action.send(req,res,'/Index/financings',params,'GET',function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //市场决策
    router.all('/shapan/api/adverShow',function(req,res){

        var group_mid = req.param('group_mid');
        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");
        var advertising_expenditure = req.param('advertising_expenditure');
        var agency_price = req.param('agency_price');
        var terminal_price = req.param('terminal_price');
        var market_value = req.param('market_value');
        var production_name = req.param('production_name');
        var market = req.param('market');

        var params={
            activity_mid:activity_mid,
            year_id:year_id,
            advertising_expenditure:advertising_expenditure,
            agency_price:agency_price,
            terminal_price:terminal_price,
            market_value:market_value,
            production_name:production_name,
            group_mid:group_mid,
            market:market
        };

        Action.send(req,res,'/Advert/adverShow',params,'GET',function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //其他决策
    router.all('/shapan/api/OtherDecisionsAdd',function(req,res){

        var group_mid = req.param('group_mid');
        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");
        var tiexian = req.param('tiexian');
        var baoxian = req.param('baoxian');
        var fajin = req.param('fajin');

        var params={
            activity_mid:activity_mid,
            year_id:year_id,
            tiexian:tiexian,
            baoxian:baoxian,
            fajin:fajin,
            group_mid:group_mid
        };

        Action.send(req,res,'/OtherDecisions/OtherDecisionsAdd',params,'GET',function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //输入研发决策
    router.all('/shapan/api/ResearchesEdit',function(req,res){

        var mid = req.param('mid');
        var research_money = req.param('research_money');
        var research_type=req.param("research_type");
        var research_reslut=req.param("research_reslut");
        var activity_mid=req.param("activity_mid");

        var params={
            mid:mid,
            research_money:research_money,
            research_type:research_type,
            research_reslut:research_reslut,
            activity_mid:activity_mid
        };

        Action.send(req,res,'/Researches/ResearchesEdit',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //研发响应能力排名
    router.all('/shapan/api/responseCapability',function(req,res){

        var year_id = req.param('year_id');
        var activity_mid = req.param('activity_mid');

        var params={
            year_id:year_id,
            activity_mid:activity_mid
        };

        Action.send(req,res,'/Researches/responseCapability',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //选单排名1
    router.all('/shapan/api/selectMenuOne',function(req,res){

        var year_id = req.param('year_id');
        var activity_mid = req.param('activity_mid');
        var production_name = req.param('production_name');
        var market = req.param('market');

        var params={
            year_id:year_id,
            activity_mid:activity_mid,
            production_name:production_name,
            market:market
        };

        Action.send(req,res,'/Advert/selectMenuOne',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //选单排名2
    router.all('/shapan/api/selectMenuTwo',function(req,res){

        var year_id = req.param('year_id');
        var activity_mid = req.param('activity_mid');
        var production_name = req.param('production_name');
        var market = req.param('market');

        var params={
            year_id:year_id,
            activity_mid:activity_mid,
            production_name:production_name,
            market:market
        };

        Action.send(req,res,'/Advert/selectMenuTwo',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).json(json);
            }else{
                res.status(200).send(data);
            }
        })
    });

    //获取招标投标单子
    router.all('/shapan/api/bidding',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var pro_name=req.param("pro_name");
        var market=req.param("market");
        var channel=req.param("channel");
        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");
        if(!page)
            page=1;
        if(!rows)
            rows=10;

        var params={
            activity_mid:activity_mid,
            year_id:year_id,
            pageIndex:page,
            pageSize:rows
        };
        if(pro_name!='undefined') {
            params.pro_name = pro_name;
        }
        if(market!='undefined') {
            params.market = market;
        }
        if(channel!='undefined') {
            params.channel = channel;
        }

        Action.send(req,res,'/Index/menuShow',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //选单
    router.all('/shapan/api/selectMenu',function(req,res){

        var group_mid = req.param('group_mid');
        var menu_mid = req.param('menu_mid');

        var params={
            group_mid:group_mid,
            menu_mid:menu_mid
        };

        Action.send(req,res,'/Group/selectMenu',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //获取选单产品名称 没用
    router.all('/shapan/api/proNameShow',function(req,res){

        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");

        var params={
            activity_mid:activity_mid,
            year_id:year_id
        };

        Action.send(req,res,'/Menu/proNameShow',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //获取选单需求市场 没用
    router.all('/shapan/api/marketShow',function(req,res){

        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");

        var params={
            activity_mid:activity_mid,
            year_id:year_id
        };

        Action.send(req,res,'/Menu/marketShow',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //获取选单渠道 没用
    router.all('/shapan/api/channelShow',function(req,res){

        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");

        var params={
            activity_mid:activity_mid,
            year_id:year_id
        };

        Action.send(req,res,'/Menu/channelShow',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //奖励小红旗
    router.all('/shapan/api/teamCombatCapability',function(req,res){

        var year_id=req.param("year_id");
        var group_mid=req.param("group_mid");
        var redflag_count=req.param("redflag_count");

        var params={
            year_id:year_id,
            group_mid:group_mid,
            redflag_count:redflag_count
        };

        Action.send(req,res,'/Group/rewardGroup',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //额外奖励
    router.all('/shapan/api/ExtraBonusAdd',function(req,res){

        var year_id=req.param("year_id");
        var group_mid=req.param("group_mid");
        var extraBonuses_mid=req.param("extraBonuses_mid");
        var money=req.param("money");
        var activity_mid=req.param("activity_mid");

        var params={
            year_id:year_id,
            group_mid:group_mid,
            money:money,
            extraBonuses_mid:extraBonuses_mid,
            activity_mid:activity_mid
        };

        Action.send(req,res,'/ExtraBonus/ExtraBonusAdd',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //生成团队排名报表
    router.all('/shapan/api/TeamRankingAdd',function(req,res){

        var year_id=req.param("year_id");
        var activity_mid=req.param("activity_mid");

        var params={
            year_id:year_id,
            activity_mid:activity_mid
        };

        Action.send(req,res,'/TeamRanking/TeamRankingAdd',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //生成资金盘点表和购产销能力表
    router.all('/shapan/api/CapitalAdd',function(req,res){

        var year_id=req.param("year_id");
        var activity_mid=req.param("activity_mid");

        var params={
            year_id:year_id,
            activity_mid:activity_mid
        };

        Action.send(req,res,'/Capital/CapitalAdd',params,'GET',function(res,data){
            var json={code:1};
            var str=JSON.stringify(json);
            res.send(str);

            //var json=JSON.parse(data);
            //
            //if(json.data===""||json.data===null){
            //    res.status(200).json(json);
            //}
            //else{
            //    res.status(200).json(json);
            //}
        })
    });

    //生成净利润报表
    router.all('/shapan/api/npadd',function(req,res){

        var year_id=req.param("year_id");
        var activity_mid=req.param("activity_mid");

        var params={
            year_id:year_id,
            activity_mid:activity_mid
        };

        Action.send(req,res,'/Np/npAdd',params,'GET',function(res,data){
            var json={code:1};
            //var json=JSON.parse(data);
            //
            //if(json.data===""||json.data===null){
               res.status(200).json(json);
            //}
            //else{
            //    res.status(200).json(json);
            //}
        })
    });

    //展示团队排名报表
    router.all('/shapan/api/TeamRankingShow',function(req,res){

        var year_id=req.param("year_id");
        var activity_mid=req.param("activity_mid");

        var params={
            year_id:year_id,
            activity_mid:activity_mid
        };

        Action.send(req,res,'/TeamRanking/TeamRankingShow',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //年度总结
    router.all('/shapan/api/userIndividual',function(req,res){

        var year_id=req.param("year_id");
        var activity_mid=req.param("activity_mid");
        var page = req.param('page');
        var rows = req.param('rows');
        var group_mid = req.param('group_mid');

        var params={
            year_id:year_id,
            activity_mid:activity_mid,
            pageIndex:page,
            pageSize:rows,
            group_mid:group_mid
        };

        Action.send(req,res,'/Index/userIndividual',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //小红旗修改
    router.all('/shapan/api/beltlineUpdate',function(req,res){

        var id = req.param('id');
        var redflag = req.param('redflag');
        var quotiety = req.param('quotiety');

        var params={
            id:id,
            redflag:redflag,
            quotiety:quotiety
        };

        Action.send(req,res,'/Index/beltlineUpdate',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //生成现金回报
    router.all('/shapan/api/cashReturnAdd',function(req,res){

        var activity_mid=req.param("activity_mid");
        var year_id=req.param("year_id");

        var params={
            activity_mid:activity_mid,
            year_id:year_id
        };

        Action.send(req,res,'/Index/cashReturnAdd',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });

    //现金回报展示
    router.all('/shapan/api/cashReturnShow',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var group_mid = req.param('group_mid');
        var year_id = req.param('year_id');
        var activity_mid = req.param('activity_mid');

        if(group_mid=="undefined"){
            group_mid="";
        }
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var params={
            pageIndex:page,
            pageSize:rows,
            year_id:year_id,
            activity_mid:activity_mid
        };

        Action.send(req,res,'/Index/cashReturnShow',params,'GET',function(res,data){

            var json=JSON.parse(data);

            if(json.data===""||json.data===null){
                res.status(200).json(json);
            }
            else{
                res.status(200).json(json);
            }
        })
    });
};
